function deleteBlog(data) {
    Swal.fire({
        title: '确认删除这篇博客?',
        text: "你在尝试删除一篇博客!",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes'
    }).then((result) => {
        if (result.value) {
            $.ajax({
                url: "/admin/deleteBlog",
                type: "delete",
                data: {"id": data},
                success: function (data) {
                    if (data === 0) {
                        Swal.fire({
                            icon: 'error',
                            title: '删除失败',
                            allowOutsideClick: false,
                        }).then($(".swal2-actions button").click(function () {
                            history.go();
                        }))
                    } else {
                        Swal.fire({
                            icon: 'success',
                            title: '删除成功',
                            allowOutsideClick: false,
                        }).then($(".swal2-actions button").click(function () {
                            history.go();
                        }))
                    }
                }
            })
        }
    })

}


function deleteBlogById() {
    Swal.fire({
        title: '确认删除选中的博客?',
        text: "你在尝试删除选中的博客!",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes'
    }).then((result) => {
        if (result.value) {
            let box = new Array();
            let checkboxes = $("#tbody  input[type=checkbox]:checked");
            box.push("First");
            for (let i = 0; i < checkboxes.length; i++) {
                box.push(checkboxes[i].value)
            }
            box.push("final")
            let s = JSON.stringify(box);
            $.ajax({
                url: "/admin/deleteBlogByIds",
                type: "delete",
                dataType: "json",
                data: {"checked": s},
                success: function (data) {
                    if (data !== 0) {
                        Swal.fire({
                            icon: 'success',
                            title: '删除成功',
                            allowOutsideClick: false,
                        }).then($(".swal2-actions button").click(function () {
                            history.go();
                        }))
                    } else {
                        Swal.fire({
                            icon: 'error',
                            title: '删除失败',
                            allowOutsideClick: false,
                        }).then($(".swal2-actions button").click(function () {
                            history.go();
                        }))
                    }
                },
                error: function () {
                    alert("cctv")
                }
            })
        }
    })
}


function Sorry() {
    Swal.fire({
        icon: 'error',
        title: '这个模块由于主人技术不够，就没做了😀',
        allowOutsideClick: false,
    }).then($(".swal2-actions button").click(function () {
        history.go();
    }))
}

function alertBlogAhthen(date) {
    let box = new Array();
    let checkboxes = $("#tbody  input[type=checkbox]:checked");
    if (checkboxes != null) {
        box.push("First");
        for (let i = 0; i < checkboxes.length; i++) {
            box.push(checkboxes[i].value)
        }
        box.push("final")
        let s = JSON.stringify(box);
        $.ajax({
            url: "/admin/alertBlogAnthen",
            type: "GET",
            dataType: "json",
            data: {"checked": s, "status": date},
            success: function (data) {
                if (data > 0) {
                    Swal.fire({
                        icon: 'success',
                        title: '修改成功',
                        allowOutsideClick: false,
                    }).then($(".swal2-actions button").click(function () {
                        history.go();
                    }))
                }
            }
        })
    } else {
        Swal.fire({
            icon: 'success',
            title: '你啥也没选中😀！！！',
            allowOutsideClick: false,
        })
    }
}


function admin_search(data) {
    $.ajax({
        url: "/admin/searchBlog/",
        type: "GET",
        dataType: "json",
        data: {"key": data, "value": $("#admin_search").val()},
        success: function (data) {
            if (data>0){
                history.go();
            }
        }
    })
}